using System;
using System.Collections.Generic;
using System.Management;
using System.Net;
using System.Text;

namespace Universe.Farm
{
    public class CommunicationParameters
    {
        public bool IsBroadcast;
        public int Port;
        public ICollection<IPAddress> IgnoreList = new List<IPAddress>();
        public ICollection<IPAddress> PeerList = new List<IPAddress>();
        public IPAddress Group;

        public int ServicePort;
        public CommunicationIntegrityAlgorithm IntegrityAlgorithm = CommunicationIntegrityAlgorithm.None;
        public ICollection<IPAddress> ServiceAddress = new List<IPAddress>();

        public static CommunicationParameters Default
        {
            get
            {
                CommunicationParameters ret = new CommunicationParameters();
                ret.IsBroadcast = true;
                ret.ServiceAddress.Add(IPAddress.Any);
                ret.ServicePort = ret.Port = DefaultPort;
                return ret;
            }
        }

        public static readonly int DefaultPort = 50505;

        public enum CommunicationIntegrityAlgorithm : byte
        {
            None,
            MD5,
            SHA1,
            SHA256,
            SHA384,
            SHA512
        }

        public static string ComputerID
        {
            get
            {
                string domain = null;
                using (ManagementObjectSearcher search = new ManagementObjectSearcher("Select Domain From Win32_ComputerSystem"))
                    foreach (ManagementBaseObject o in search.Get())
                    {
                        object rName = o["Domain"];
                        if (rName is string)
                            domain = (string) rName;

                        break;
                    }

                return
                    string.IsNullOrEmpty(domain)
                        ? Environment.MachineName
                        : Environment.MachineName + "@" + domain;
                
            }
        }
    }
}